/**
 * desc：
 * author：王文军
 * date：  2022/5/1 上午9:59
 */
"use strict";
const { Context } = require("egg");
module.exports = {
  formatName(name) {
    let _name = name;
    if (_name && _name.startsWith("@") && _name.indexOf("/") > 0) {
      // @imooc-cli-dev/component-test ->
      // imooc-cli-dev_component-test
      const nameArray = _name.split("/");
      _name = nameArray.join("_").replace("@", "");
    }
    return _name;
  },
  getTokenValue(authorization) {
    if (typeof authorization === "string") {
      const parts = authorization.trim().split(" ");
      if (parts.length === 2) {
        const scheme = parts[0];
        const credentials = parts[1];
        if (/^Bearer$/i.test(scheme)) {
          return credentials;
        }
      } else {
        return false;
      }
    } else {
      return false;
    }
  },
};
